<!--
 * @Author: your name
 * @Date: 2022-02-23 16:06:20
 * @LastEditTime: 2022-02-23 16:06:20
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \dreamUi\src\componets\echarts\Body.vue
-->
<template>
  <!--主容器-->
  <el-container class="main-class">
    <!--头部信息-->
      <el-header>
        <el-row style="height: 100%;">
          <!--头像-->
          <el-col :span="2" style="height: 100%;">
            <el-avatar :size="60" :src= 'avatar' />
          </el-col>
          <!-- 项目名称 -->
          <el-col :span="14" class="head-text">
            青春筑梦之旅后台管理界面
            <span>--管理员：{{name}}</span>
          </el-col>
          <!-- 退出按钮 -->
          <el-col :span="7" class="logout">
            <el-button type="info" @click="logout">退出登录</el-button>
          </el-col>
        </el-row>
      </el-header>
      <!--主体容器-->
      <el-container>
        <!--侧边栏-->
        <el-aside :width="menuActive ? '200px' : '80px'">
          <div style="font-size: 23px; cursor: pointer;" @click="menuActive = !menuActive">
            <i class="el-icon-s-fold"/>
          </div>
          <el-menu :default-active= "activePath" class="el-menu-vertical-demo" unique-opened router :collapse="!menuActive" >
            <el-submenu v-for="(parentMenu, index) in menus" :key="index" :index="index + ''">
                <template slot="title">
                  <i :class="parentMenu.icon" style="margin-right: 7px;"/>
                  <span>{{ parentMenu.title }}</span>
                </template>
              <el-menu-item v-for="(childrenMenu,i) in parentMenu.children" :key="i" :index="childrenMenu.path" @click="savePath(childrenMenu.path)">
                <template slot="title">
                  <i :class="childrenMenu.icon" style="margin-right: 7px;"/>
                  <span>{{ childrenMenu.title }}</span>
                </template> 
              </el-menu-item>
          </el-submenu>
        </el-menu>
        </el-aside>
        <!--主体-->
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-for="(item, index) in $router.currentRoute.matched" :key="index">{{item.meta.title}}</el-breadcrumb-item>
          </el-breadcrumb>
          <span v-show="$router.currentRoute.path === '/home'">欢迎来到青春之旅筑梦平台后台管理界面</span>
          <!-- 作为主体子路由 -->
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: 'home',

  data() {
    return {
      administrators: " ",
      // 是否展开菜单
      menuActive: true,
      // 激活的菜单
      activePath: sessionStorage.getItem('activePath')
    };
  },

  computed: {
    ...mapState(['name','avatar','menus'])
  },
  created() {
    // console.log('menus', this.menus)
  },
  mounted() {

  },

  methods: {
    logout() {
      this.$confirm('您将退出系统, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 调用退出登录接口
          this.$ajax.get('/user/logout').then((res) => {
            // 清空本地缓存
            sessionStorage.clear();
            // 跳转到登录界面
            this.$router.replace('/login');
            this.$message({
              type: 'success',
              message: '退出成功'
            })
          },(err) => {
            this.$message({
              type: 'info',
              message: '退出系统失败，请联系管理员'
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出登录'
          });          
        });
    },
    // 保存被激活的链接
    savePath(path) {
      sessionStorage.setItem('activePath',path);
      this.activePath = path;
    }
  },
};
</script>

<style scoped>
.el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
}
  
.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
}
  
.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
}
/** 当前页主容器样式 */
.main-class {
  height: 100%;
  width: 100%;
}
.head-text {
  text-align: left;
  margin-left: 1rem;
  font-size: 1.5rem;
  font-family: 华文行楷;
}
.logout {
  text-align: right;
}
.el-submenu .el-menu-item {
  padding: 0;
}
</style>